package com.zfei;

import org.apache.calcite.adapter.mongodb.MongoSchema;

import java.net.URL;
import java.sql.*;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

public class TestMP {
    protected static final URL MODEL = TestMP.class.getResource("/mongo-model.json");
    protected static final int ZIPS_SIZE = 149;
    public static final MongoDatabasePolicy POLICY = MongoDatabasePolicy.create();
    private static MongoSchema schema;

    public static void main(String[] args) {
        try {
            Class. forName("org.apache.calcite.jdbc.Driver");
        } catch (ClassNotFoundException e1) {
            e1.printStackTrace();
        }
        Properties info = new Properties();
//        info.setProperty("database","data_fusion");
//        info.setProperty("username","zkxbxdb");
//        info.setProperty("passward","zkxbx2018!");

        try {
            Connection connection =
                    DriverManager.getConnection("jdbc:calcite:model=E:\\javawork\\xexPlus3.1\\xexPlusOauth\\test_circite\\src\\main\\resources\\tt,json", info );
            Statement st = connection.createStatement();
            ResultSet result =st.executeQuery("select cast(_MAP['user_id'] AS varchar(70)) AS user_id from \"v1_request_rule\" ");
            ResultSetMetaData rsmd = result.getMetaData();
            while (result.next()){
                Map<String,Object> map = new HashMap<String,Object>();
                for(int i = 0 ; i < rsmd.getColumnCount() ; i++){
                    String col_name = rsmd.getColumnName(i+1);
                    Object col_value = result.getObject(col_name);
                    if(col_value == null){
                        col_value = "";
                    }
                    map.put(col_name, col_value);
                }


                System.out.println(map.toString());
            }
        }catch ( Exception e){
            e.printStackTrace();
        }

    }
}
